const mysql=require("mysql");
const db=require("../model/config").database;
const pool=mysql.createPool(db)

const query=(sql,sucCb,errCb)=>{
  pool.getConnection((err,conn)=>{
    if(err){
      errCb({
        code:"500",
        message:"请求失败",
        data:err
      })
    }else{
      conn.query(sql,(err,result)=>{
        if(err){
          errCb({
            code:"500",
            message:'请求失败',
            data:err
          })
        }else{
          sucCb(result);
          conn.release();
        }
      })
    }
  })
}
module.exports=query;